# 
# To change this template, choose Tools | Templates
# and open the template in the editor.
 

class Output
  attr_reader :type
  def initialize
    @type = "NA"
    
  end
end

class OutputVm  < Output
  def initialize (type,k8055instance,k8055channel)
    @k8055 = k8055instance
    @channel = k8055channel
    @type = type
    @aoEuMin = 0
    @aoEuMax = 100
    @aoRawMin = 0
    @aoRawMax = 255
  end
  def set(value)
    if(@type.upcase=="DO")
      if(value==1 or value==true)
        @k8055.setDigitalChannel(@channel)
      else
        @k8055.clearDigitalChannel(@channel)
      end
    elsif(@type.upcase=="AO")
      rangeEu = @aoEuMax-@aoEuMin
      rangeRaw = @aoRawMax-@aoRawMin
      outvalue = ((value.to_f/rangeEu.to_f)*rangeRaw.to_f).to_i
      @k8055.outputAnalogChannel(@channel,outvalue)
    end
  end
end